package com.shop.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.entity.BulkMerchantReturn;
import com.shop.mapper.BulkMerchantReturnMapper;
import com.shop.mapper.BulkReturnDetailMapper;
import com.shop.model.PageParam;
import com.shop.model.vo.Rsp;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@AllArgsConstructor
public class BulkMerchantReturnService {
    private final BulkMerchantReturnMapper bulkMerchantReturnMapper;
    private final BulkReturnDetailMapper bulkReturnDetailMapper;
        /**
         * @author clh
         * @description
         * @date  2020/11/30 15:52
         * @return {@link Rsp}
         **/
//    public Rsp insertSelective(BulkMerchantReturn bulkMerchantReturn,
//                               Integer merchantId,
//                               Integer supplierId){
//        //设置商家id
//        bulkMerchantReturn.setMerchantId(merchantId);
//        //设置供应商id
//        bulkMerchantReturn.setSupplyId(supplierId);
//        //创建退货订单
//        bulkMerchantReturnMapper.insertSelective(bulkMerchantReturn);
//        //创建退货订单详情集合
//        ArrayList<BulkReturnDetail> list = new ArrayList<>();
//        double total=0;
//        int num=0;
//        //遍历获取退货订单信息
//        for (BulkReturnDetail bulkReturnDetail:list) {
//            bulkReturnDetail.setReturnId(bulkMerchantReturn.getId());
//            double v = bulkReturnDetail.getGoodsCount() * bulkReturnDetail.getGoodsPrice();
//            bulkReturnDetail.setGoodsTotal(v);
//            total+=v;
//            Integer count = bulkReturnDetail.getGoodsCount();
//            num+=count;
//        }
//        bulkMerchantReturn.setCount(num);
//        bulkMerchantReturn.setTotal(total);
//        bulkReturnDetailMapper.insertList(list);
//        bulkMerchantReturnMapper.updateById(bulkMerchantReturn);
//
//        return Rsp.success(true).msg("退货订单生产成功");
//    }
        /**
         * @author clh
         * @description 分页
         * @date  2020/11/30 19:40
         * @param pageParam
         * @return {@link PageInfo}
         **/
        public PageInfo searchSomeByPageReturn(PageParam<BulkMerchantReturn> pageParam){
            PageHelper.startPage(pageParam.getPageNum(), pageParam.getPageSize());
            for (int i = 0; i <pageParam.getOrderParams().length ; i++) {
                PageHelper.orderBy(pageParam.getOrderParams()[i]);
            }

            List<BulkMerchantReturn> merchantReturnList = bulkMerchantReturnMapper.searchSomeByPageReturn(pageParam.getSuperSearchKeyWord(), pageParam.getModel());
            PageInfo<BulkMerchantReturn> pageInfo = new PageInfo<>(merchantReturnList);

            return pageInfo;
        }
        /**
         * @author clh
         * @description 修改状态
         * @date  2020/11/30 19:40
         * @param bulkMerchantReturn
         * @return {@link Rsp}
         **/
        public Rsp updateStatusOne(BulkMerchantReturn bulkMerchantReturn){

            return Rsp.success(bulkMerchantReturnMapper.updateStatusOne(bulkMerchantReturn));
        }
}
